<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2012 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id: Behavior.class.php 2702 2012-02-02 12:35:01Z liu21st $
/**
 +------------------------------------------------------------------------------
 * ThinkPHP Behavior基础类
 +------------------------------------------------------------------------------
 * @category   Think
 * @package  Think
 * @subpackage  Util
 * @author liu21st <liu21st@gmail.com>
 * @version  $Id: Behavior.class.php 2702 2012-02-02 12:35:01Z liu21st $
 * @last modify  2012-12-04 11:33:20 by mashanling
 +------------------------------------------------------------------------------
 */
abstract class Behavior {

    protected $options = array();//行为参数和配置参数设置相同

     /**
     * 执行行为 run方法是Behavior唯一的接口
     *
     * @last modify 2012-12-04 11:34:07 by mashanling
     *
     * @access abstract,public
     *
     * @param array $params 参数
     *
     * @return mixed
     */
    abstract public function run(&$params);

    /**
     * 构造函数
     *
     * @last modify 2012-12-04 11:35:22 by mashanling
     *
     * @access public
     *
     * @return void 无返回值
     */
    public function __construct() {

        if (!empty($this->options)) {

            foreach ($this->options as $name => $val) {

                if (null !== C($name)) { // 参数已设置,则覆盖行为参数
                    $this->options[$name] = C($name);
                }
                else {//参数未设置,则传入默认值到配置
                    C($name, $val);
                }
            }

            array_change_key_case($this->options);
        }
    }

    /**
     * 获取参数值
     *
     * @last modify 2012-12-04 11:36:46 by mashanling
     *
     * @access public
     *
     * @return mixed 参数值
     */
    public function __get($name) {
        return $this->options[strtolower($name)];
    }
}